import json
import pygame

class Config:
    def __init__(self):
        self.default_config = {
            'keys': {
                'left': pygame.K_LEFT,
                'right': pygame.K_RIGHT,
                'down': pygame.K_DOWN,
                'rotate': pygame.K_UP,
                'drop': pygame.K_SPACE,
                'pause': pygame.K_p
            },
            'volume': 0.7,
            'fullscreen': False,
            'high_score': 0
        }
        self.config = self.load_config()
        
    def load_config(self):
        try:
            with open('config.json', 'r') as f:
                return json.load(f)
        except:
            return self.default_config.copy()
            
    def save_config(self):
        with open('config.json', 'w') as f:
            json.dump(self.config, f)
            
    def get_key(self, action):
        return self.config['keys'].get(action, self.default_config['keys'][action])
        
    def update_high_score(self, score):
        if score > self.config['high_score']:
            self.config['high_score'] = score
            self.save_config() 